package com.hp.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

public abstract class CommonController {

	/**得到request对象
	 * @return
	 */
	public HttpServletRequest getRequest() {
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		return request;
	}
	
	/**
	 * @author: xing
	 * @return: String
	 * @description:抛出异常
	 */
	@ExceptionHandler(Exception.class)
	@ResponseBody
	public String returnException(Exception e) {
		System.out.println(e.toString());
		return e.getMessage();
	}
}
